package com.gluck.cases.app.biz.impl.impl;

import com.github.pagehelper.PageInfo;
import com.gluck.cases.app.biz.impl.CasesApiService;
import com.gluck.cases.common.utils.enums.BizSerErrorEnum;
import com.gluck.cases.common.utils.utils.AssertUtil;
import com.gluck.cases.core.block.CasesApiBlock;
import com.gluck.cases.core.modal.dto.CasesApiDTO;
import com.gluck.cases.core.modal.entity.CasesApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName CasesApiServiceImpl
 * @Desc TODO
 * @Author shiyongzhe
 * @Date 2022/5/28 - 7:21 下午
 **/
@Service
public class CasesApiServiceImpl implements CasesApiService {

    @Autowired
    private CasesApiBlock casesApiBlock;

    @Override
    public PageInfo<CasesApiDTO> queryList(CasesApiDTO dto, int page, int size) {
        return casesApiBlock.queryByCondition(dto, page, size);
    }

    @Override
    public CasesApiDTO queryDetailById(Long id) {
        CasesApiDTO dto = casesApiBlock.queryById(id);
        return dto;
    }

    @Override
    public boolean updateCasesApi(CasesApiDTO dto) {
        boolean update = casesApiBlock.updateByCondition(dto);
        AssertUtil.isFalse(update, BizSerErrorEnum.CASES_API_UPDATE_ERROR);
        return true;
    }

    @Override
    public boolean deleteCasesApis(List<Long> ids) {
        ids.stream().forEach(id -> {
            boolean result = casesApiBlock.deleteById(id);
            AssertUtil.isFalse(result, BizSerErrorEnum.CASES_API_DELETE_ERROR);
        });
        return true;
    }
}
